const userServer = require("../../service/userService");

const getUserList = async (ctx, next) => {
	let res = await userServer.getUserList();
	ctx.body = {
		code: res.code,
		message: res.message,
		data: res.data,
	};
};

// 全部订单
const gettransList = async (ctx, next) => {
	let res = await userServer.gettrainList();
	ctx.body = {
		code: res.code,
		message: res.message,
		data: res.data,
	};
};

// 删除订单
const deleteList = async (ctx, next) => {
	let res = await userServer.deleteList({
		id: ctx.request.body.id
	});
	ctx.body = {
		code: res.code,
		message: res.message,
	};
};

// 登录
const logindata = async (ctx, next) => {
	console.log("ctx", ctx.query);
	let res = await userServer.loginList({
		username: ctx.query.username,
		password: ctx.query.password,
	});
	ctx.body = {
		code: res.code,
		message: res.message,
		data: res.data,
		token:res.token
	};
	console.log(res);
};

// 注册
const righrighzhuce = async (ctx, next) => {
	console.log("ctx", ctx.request);
	let res = await userServer.righzhuce({
		username: ctx.request.body.username,
		password: ctx.request.body.password,
		nickname: ctx.request.body.nickname,
		avatar: ctx.request.body.avatar,
		age: ctx.request.body.age,
		phone: ctx.request.body.phone,
		email: ctx.request.body.email,

	});
	ctx.body = {
		code: res.code,
		message: res.message,
	};
};

// 乘客
const chenkedata = async (ctx, next) => {
	let res = await userServer.chenke();
	ctx.body = {
		code: res.code,
		message: res.message,
		data: res.data,
	};
};
// 旅行资讯
const TravelNews = async (ctx, next) => {
	let res = await userServer.getTravelNews();
	ctx.body = {
		code: res.code,
		message: res.message,
		data: res.data,
	};
};
module.exports = {
	getUserList,
	gettransList,
	deleteList,
	logindata,
	righrighzhuce,
	chenkedata,
	TravelNews
};